#include <views/abstractView.h>

AbstractView::AbstractView(QWidget *parent) : QWidget(parent)
{
	network = NULL;
	connect(parent,SIGNAL(colormapChanged()),this,SLOT(on_colormapChanged()));
	connect(parent,SIGNAL(matrixChanged()),this,SLOT(on_matrixChanged()));
}

QVector<AnatomicalLink*>& AbstractView::getSelection() const
{
	return network->getSelection();
}

void AbstractView::setSelection(const SelectedLinks& links)
{
	setRenderMode(FunctionalNetwork::LinkRenderer);
	network->setSelection(links);
}

void AbstractView::setSelection(const SelectedRegions& regions)
{
	setRenderMode(FunctionalNetwork::RegionRenderer);
	network->setSelection(regions);
}

bool AbstractView::isSelected(AnatomicalRegion *reg)
{
    for(int i = 0;i < network->getSelection().size();i++)
		if(network->getSelection().at(i)->regionA()->equals(reg) ||
			network->getSelection().at(i)->regionB()->equals(reg))
            return true;
    return false;
}

bool AbstractView::isSelected(AnatomicalLink *link)
{
	bool contains = network->getSelection().contains(link);
	return contains;
}

void AbstractView::setNetwork(FunctionalNetwork *net)
{
	network = net;
	connect(network,SIGNAL(matrixChanged()),this,SLOT(on_matrixChanged()));
	connect(network,SIGNAL(selectionChanged()),this,SLOT(on_selectionChanged()));
    aTemplate = network->getTemplate();
}